package com.qidian.mes.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.common.pojo.MESResult;
import com.qidian.common.util.Constant;
import com.qidian.common.util.JSONTools;
import com.qidian.common.util.ThreadPoolUtil;
import com.qidian.mes.pojo.Dict;
import com.qidian.mes.pojo.DictData;
import com.qidian.mes.sys.mapper.DictDataMapper;
import com.qidian.mes.sys.service.DictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Description
 * @Time 2024/10/12 上午 10:41
 */
@Service
public class DictDataServiceImpl implements DictDataService {
    @Autowired
    private DictDataMapper dictDataMapper;
    @Override
    public MESResult save(DictData dictData) {
        // 查重
        DictData tempDict = dictDataMapper.selectByTag(dictData.getDictDataTag());
        if(tempDict != null)
            return MESResult.error(Constant.RESPONSE_STATUS_REPEAT,"字典项标签重复");
        if(dictDataMapper.selectByValue(dictData.getDictDataValue()) != null)
            return MESResult.error(Constant.RESPONSE_STATUS_REPEAT,"字典项键值重复重复");
        return MESResult.isSuccess(dictDataMapper.insert(dictData));
    }

    @Override
    public MESResult list(Long dictId) {
        return MESResult.success(dictDataMapper.selectList(dictId));
    }

    @Override
    public MESResult get(Long dictId) {
        return MESResult.success(dictDataMapper.selectById(dictId));
    }

    @Override
    public MESResult update(DictData dictData) {
        // 查重
        DictData tempDictData = dictDataMapper.selectByTag(dictData.getDictDataTag());
        if(tempDictData != null && !tempDictData.getDictDataId().equals(dictData.getDictDataId()))
            return MESResult.error(Constant.RESPONSE_STATUS_REPEAT,"字典名称重复");
        tempDictData = dictDataMapper.selectByValue(dictData.getDictDataValue());
        if(tempDictData != null && !tempDictData.getDictDataId().equals(dictData.getDictDataId()))
            return MESResult.error(Constant.RESPONSE_STATUS_REPEAT,"字典类型重复");
        int result = dictDataMapper.updateById(dictData);
        return MESResult.isSuccess(result);
    }

    @Override
    public MESResult delete(Long dictDataId) {
        int i = dictDataMapper.deletesById(new Long[]{dictDataId});
        return MESResult.success();
    }

    @Override
    public MESResult deletes(Long[] dictIds) {
        return MESResult.success(dictDataMapper.deletesById(dictIds));
    }


}
